home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / hgraphic.zip / GO.C < prev    next >
Text File  |  1988-04-12  |  3KB  |  133 lines

  1. /*
  2.     File:      go.c
  3.     Author:   Ben Bederson
  4.     Date:      April, 1988
  5.     Function: Tests Hercules graphics routines
  6.           Examples of how to use routines
  7.  
  8.     Needs data files s1, s2, s3, and s4.
  9.  
  10.     Compile with large model (/AL) for use with graphics routines.
  11. */
  12. #include <stdio.h>
  13. #include <malloc.h>
  14. #include "graphics.h"
  15.  
  16. struct shape_type shape;
  17. struct shape_type shape1;
  18. struct shape_type shape2;
  19. struct shape_type shape3;
  20. struct shape_type shape4;
  21.  
  22. main(argc,argv)
  23. int argc;
  24. char *argv[];
  25. {
  26.   int i,j,k;
  27.   int m;
  28.   int dir;
  29.   int temp;
  30.   int tempx,tempy;
  31.   int att,chr;
  32.  
  33.   read_shape("s1",&shape);
  34.   graphics();
  35.   fill_screen();
  36.   grcls();
  37.   line(0,0,719,0);    /* sides of screen */
  38.   line(0,0,0,347);
  39.   line(719,0,719,347); /* top and bottom of screen */
  40.   line(0,347,719,347);
  41.   getch();
  42.   draw(shape,16,300,WHITE);
  43.   for (j=1; j<=2; j++) {
  44.     for (i=16; i<600; i+=8) {
  45.       shift_right_block(shape,i,300);
  46.       if (argc > 3) getch();
  47.     }
  48.     for (k=300; k>50; k-=8) {
  49.       shift_up_block(shape,i,k);
  50.       if (argc > 3) getch();
  51.     }
  52.     for (m=i; m>16; m-=8) {
  53.       shift_left_block(shape,m,k);
  54.       if (argc > 3) getch();
  55.     }
  56.     for (i=k; i<300; i+=8) {
  57.       shift_down_block(shape,m,i);
  58.       if (argc > 3) getch();
  59.     }
  60.   }
  61.   draw(shape,m,i,XOR);
  62.   getch();
  63.   read_shape("s1",&shape1);
  64.   read_shape("s2",&shape2);
  65.   read_shape("s3",&shape3);
  66.   read_shape("s4",&shape4);
  67.   draw_block(shape1,16,304,XOR);
  68.   j = 2;
  69.   dir = 1;
  70.   for (i=16; i<=600; i+=8) {
  71.     switch(j) {
  72.       case 1:
  73.     draw_block(shape1,i+8,304,XOR);
  74.     draw_block(((dir == 1) ? shape1 : shape2),i,304,XOR);
  75.     break;
  76.       case 2:
  77.     draw_block(shape2,i+8,304,XOR);
  78.     draw_block(((dir == 1) ? shape1 : shape3),i,304,XOR);
  79.     break;
  80.       case 3:
  81.     draw_block(shape3,i+8,304,XOR);
  82.     draw_block(((dir == 1) ? shape2 : shape4),i,304,XOR);
  83.     break;
  84.       case 4:
  85.     draw_block(shape4,i+8,304,XOR);
  86.     draw_block(((dir == 1) ? shape3 : shape4),i,304,XOR);
  87.     break;
  88.     }
  89.     j += dir;
  90.     if (j > 4) {
  91.       j = 4;
  92.       dir *= -1;
  93.     }
  94.     else if (j < 1) {
  95.       j = 1;
  96.       dir *= -1;
  97.     }
  98.     if (argc > 2) getch();
  99.   }
  100.   text();
  101. }
  102.  
  103. read_shape(filename,shape)
  104. char *filename;
  105. struct shape_type *shape;
  106. {
  107.   int i;
  108.   int j;
  109.   int temp;
  110.   FILE *fp;
  111.  
  112.   fp = fopen(filename,"r");
  113.   if (!fp) {
  114.     text();
  115.     printf("Error opening %s\n",filename);
  116.     exit(1);
  117.   }
  118.   fscanf(fp,"%d%d",&((*shape).x),&((*shape).y));
  119.   (*shape).shape_array = (char *)malloc((*shape).x * (*shape).y);
  120.   if ((*shape).shape_array == 0) {
  121.     text();
  122.     printf("Error: can't malloc for shape\n");
  123.     exit(1);
  124.   }
  125.   for (j=0; j<(*shape).y; j++) {
  126.     for (i=0; i<(*shape).x; i++) {
  127.       fscanf(fp,"%x",&temp);
  128.       (*shape).shape_array[j*(*shape).x + i] = (char)(temp & 0xff);
  129.     }
  130.   }
  131.   fclose(fp);
  132. }
  133.